# coding:utf-8
"""
@author: 井松
@contact: 529548204@qq.com
@file: views.py
@time: 2021/11/10 17:25
"""

def format_errors(ser= None, detail= None) -> str:
    ret = []
    data = None
    if ser:
        data = ser.errors.items()
    elif detail:
        if isinstance(detail, list):
            return '；'.join(detail)
        data = detail.items()

    if not data:
        return ''

    for k, v in data:
        if k == 'non_field_errors':
            ret.append(f'{v[0]}')
        else:
            ret.append(f'{k}: {v[0]}')
    msg = '；'.join(ret)
    return msg
